# ifndef __DIBitmap_H_
# define __DIBitmap_H_

# include "Bitmap.h"

	//
	// Device-independent bitmap (24-bit RGB).
	//

class CDIBitmap : public CBitmap {
  public:
	CDIBitmap (long _lWidth, long _lHeight);
	~CDIBitmap () {delete [] m_pBits;}

	const BITMAPINFO * GetBitmapInfo () const {return reinterpret_cast<const BITMAPINFO *> (& m_BitmapInfo);}
	      BITMAPINFO * GetBitmapInfo ()       {return reinterpret_cast<      BITMAPINFO *> (& m_BitmapInfo);}

	BYTE * GetBits () {return m_pBits;}

	long GetScanWidth () const {
		long lScanWidth = 3*m_BitmapInfo.biWidth;
		if (lScanWidth & 0x3)
			lScanWidth += 4 - (lScanWidth & 0x3);
		assert (lScanWidth % 4 == 0);
		return lScanWidth;
	}

	// Override.
	virtual BOOL StretchBlt (
		HDC _hdcDest,
		int _xDest, int _yDest, int _wDest, int _hDest,
		int _xSrc,  int _ySrc,  int _wSrc,  int _hSrc,
		DWORD _dwRop = SRCCOPY
	) const {
		return ::StretchDIBits (
			_hdcDest,
			_xDest, _yDest,                      _wDest, _hDest,
			_xSrc,  (m_lHeight - _hSrc) - _ySrc, _wSrc,  _hSrc,
			m_pBits, GetBitmapInfo (), DIB_RGB_COLORS, _dwRop
		);
	}
	virtual BOOL AlphaBlend (
		HDC _hdcDest,
		int _xDest, int _yDest, int _wDest, int _hDest,
		int _xSrc,  int _ySrc,  int _wSrc,  int _hSrc,
		BYTE _SourceConstantAlpha
	) const;

	virtual CBitmap * MakeSmall () const;

  private:
	BITMAPINFOHEADER m_BitmapInfo;
	BYTE             * m_pBits;
};

# endif // __DIBitmap_H_